package com.trace.pplos.parse.dao.dataobject;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Date;

public class CzwInfo {
    private static final Logger logger = LoggerFactory.getLogger(CzwInfo.class);

    private Integer id;

    private String addr;

    private String roomAddr;

    private String drplt;

    private String owner;

    private String ownerIdcard;

    private String ownerPhone;

    private String tenant;

    private String tenantIdcard;

    private String tenantPhone;

    private String photoPath;

    private String lng;

    private String lat;

    private String cjdw;

    private String filepath;

    private String locMapSnapPath;

    private Date gmtCreate;

    private String gmtCreateUser;

    private Date gmtModified;

    private String gmtModifiedUser;

    private Integer status;

    public CzwInfo(Integer id, String addr, String roomAddr, String drplt, String owner, String ownerIdcard, String ownerPhone, String tenant, String tenantIdcard, String tenantPhone, String photoPath, String lng, String lat, String cjdw, String filepath, String locMapSnapPath, Date gmtCreate, String gmtCreateUser, Date gmtModified, String gmtModifiedUser, Integer status) {
        this.id = id;
        this.addr = addr;
        this.roomAddr = roomAddr;
        this.drplt = drplt;
        this.owner = owner;
        this.ownerIdcard = ownerIdcard;
        this.ownerPhone = ownerPhone;
        this.tenant = tenant;
        this.tenantIdcard = tenantIdcard;
        this.tenantPhone = tenantPhone;
        this.photoPath = photoPath;
        this.lng = lng;
        this.lat = lat;
        this.cjdw = cjdw;
        this.filepath = filepath;
        this.locMapSnapPath = locMapSnapPath;
        this.gmtCreate = gmtCreate;
        this.gmtCreateUser = gmtCreateUser;
        this.gmtModified = gmtModified;
        this.gmtModifiedUser = gmtModifiedUser;
        this.status = status;
    }

    public CzwInfo() {
        super();
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getAddr() {
        return addr;
    }

    public void setAddr(String addr) {
        this.addr = addr == null ? null : addr.trim();
    }

    public String getRoomAddr() {
        return roomAddr;
    }

    public void setRoomAddr(String roomAddr) {
        this.roomAddr = roomAddr == null ? null : roomAddr.trim();
    }

    public String getDrplt() {
        return drplt;
    }

    public void setDrplt(String drplt) {
        this.drplt = drplt == null ? null : drplt.trim();
    }

    public String getOwner() {
        return owner;
    }

    public void setOwner(String owner) {
        this.owner = owner == null ? null : owner.trim();
    }

    public String getOwnerIdcard() {
        return ownerIdcard;
    }

    public void setOwnerIdcard(String ownerIdcard) {
        this.ownerIdcard = ownerIdcard == null ? null : ownerIdcard.trim();
    }

    public String getOwnerPhone() {
        return ownerPhone;
    }

    public void setOwnerPhone(String ownerPhone) {
        this.ownerPhone = ownerPhone == null ? null : ownerPhone.trim();
    }

    public String getTenant() {
        return tenant;
    }

    public void setTenant(String tenant) {
        this.tenant = tenant == null ? null : tenant.trim();
    }

    public String getTenantIdcard() {
        return tenantIdcard;
    }

    public void setTenantIdcard(String tenantIdcard) {
        this.tenantIdcard = tenantIdcard == null ? null : tenantIdcard.trim();
    }

    public String getTenantPhone() {
        return tenantPhone;
    }

    public void setTenantPhone(String tenantPhone) {
        this.tenantPhone = tenantPhone == null ? null : tenantPhone.trim();
    }

    public String getPhotoPath() {
        return photoPath;
    }

    public void setPhotoPath(String photoPath) {
        this.photoPath = photoPath == null ? null : photoPath.trim();
    }

    public String getLng() {
        return lng;
    }

    public void setLng(String lng) {
        this.lng = lng == null ? null : lng.trim();
    }

    public String getLat() {
        return lat;
    }

    public void setLat(String lat) {
        this.lat = lat == null ? null : lat.trim();
    }

    public String getCjdw() {
        return cjdw;
    }

    public void setCjdw(String cjdw) {
        this.cjdw = cjdw == null ? null : cjdw.trim();
    }

    public String getFilepath() {
        return filepath;
    }

    public void setFilepath(String filepath) {
        this.filepath = filepath == null ? null : filepath.trim();
    }

    public String getLocMapSnapPath() {
        return locMapSnapPath;
    }

    public void setLocMapSnapPath(String locMapSnapPath) {
        this.locMapSnapPath = locMapSnapPath == null ? null : locMapSnapPath.trim();
    }

    public Date getGmtCreate() {
        return gmtCreate;
    }

    public void setGmtCreate(Date gmtCreate) {
        this.gmtCreate = gmtCreate;
    }

    public String getGmtCreateUser() {
        return gmtCreateUser;
    }

    public void setGmtCreateUser(String gmtCreateUser) {
        this.gmtCreateUser = gmtCreateUser == null ? null : gmtCreateUser.trim();
    }

    public Date getGmtModified() {
        return gmtModified;
    }

    public void setGmtModified(Date gmtModified) {
        this.gmtModified = gmtModified;
    }

    public String getGmtModifiedUser() {
        return gmtModifiedUser;
    }

    public void setGmtModifiedUser(String gmtModifiedUser) {
        this.gmtModifiedUser = gmtModifiedUser == null ? null : gmtModifiedUser.trim();
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public static CzwInfo toBean(String object){
        try{
            CzwInfo info = new CzwInfo();
            JSONObject record = JSON.parseObject(object);
            info.setAddr(record.getString("address"));
            info.setRoomAddr(record.getString("address"));
            info.setDrplt(record.getString("mphm"));
            info.setOwner(record.getString("czrxm"));
            info.setOwnerIdcard(record.getString("czrsfz"));
            info.setOwnerPhone(record.getString("czrsjh"));
            info.setTenant(record.getString("czzxm"));
            info.setTenantIdcard(record.getString("czzsfz"));
            info.setTenantPhone(record.getString("czzxm"));
            info.setLng(record.getString("longitude"));
            info.setLat(record.getString("latitude"));
            //现场方位图
            String filePaths = "";
            JSONArray list = record.getJSONArray("xcfwPictureList");
            for (int i = 0; i < list.size(); i++) {
                JSONObject dataObj = list.getJSONObject(i);
                filePaths += dataObj.getString("path") +",";
            }
            info.setLocMapSnapPath(filePaths);
            //外部概览图
            filePaths = "";
            list = record.getJSONArray("xxzlPictureList");
            for (int i = 0; i < list.size(); i++) {
                JSONObject dataObj = list.getJSONObject(i);
                filePaths += dataObj.getString("path") +",";
            }
            info.setPhotoPath(filePaths);
            info.setGmtCreate(record.getDate("createdAt"));
            info.setGmtCreateUser(record.getString("createdBy"));
            //info.setGmtModified(record.getDate("modifiedAt"));
            info.setGmtModified(new Date());
            info.setGmtModifiedUser(record.getString("modifiedBy"));
            return info;
        }catch (Exception e){
            logger.error(e.getMessage(), e);
        }
        return null;
    }
}